class CreateComments < ActiveRecord::Migration
  def self.up
    create_table :comments do |t|
      t.column :comment_id, :integer
      t.column :created_at, :datetime
      t.column :user_id, :integer
      t.column :comment, :text
    end
    add_column :stories, :comments_count, :integer, :default => 0
    Story.find(:all).each do |s|
      s.update_attribute(:comments_count, s.comments.length)
    end

  end

  def self.down
    drop_table :comments
    remove_column :stories, :comments_count
  end
end
